﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using YULI.Common;

namespace YULI.Web.UI
{
    public partial class BasePage : System.Web.UI.Page
    {
        /// <summary>
        /// 获取管理员后台导航列表
        /// </summary>
        /// <returns></returns>
        protected DataTable GetAdminNav()
        {
            DataTable newdt = new DataTable();
            newdt.Columns.Add("id", Type.GetType("System.Int32"));
            newdt.Columns.Add("pid", Type.GetType("System.Int32"));
            newdt.Columns.Add("icon", Type.GetType("System.String"));
            newdt.Columns.Add("url", Type.GetType("System.String"));
            newdt.Columns.Add("name", Type.GetType("System.String"));

            //newdt.Rows.Add(1, 0, "fa fa-home", "center.aspx", "系统首页");
            //newdt.Rows.Add(2, 0, "fa fa-users", "#", "管理员管理");
            //newdt.Rows.Add(3, 0, "fa fa-cogs", "#", "系统管理");
            //newdt.Rows.Add(4, 2, "fa fa-angle-double-right", "manager/manager_list.aspx", "管理员列表");
            //newdt.Rows.Add(5, 2, "fa fa-angle-double-right", "manager/manager_log.aspx", "管理员日志");
            //newdt.Rows.Add(6, 3, "fa fa-angle-double-right", "settings/sys_config.aspx", "系统配置");

            DataTable dt = new BLL.navigation().GetList(0, YULIEnums.NavigationEnum.Admin.ToString(), 1);
            if (dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    string id = dt.Rows[i]["id"].ToString();
                    string pid = dt.Rows[i]["parent_id"].ToString();
                    string icon = "fa " + dt.Rows[i]["icon_url"].ToString();
                    string url = dt.Rows[i]["link_url"].ToString();
                    string name = dt.Rows[i]["title"].ToString();

                    newdt.Rows.Add(Convert.ToInt32(id), Convert.ToInt32(pid), icon, url, name);
                }
            }

            return newdt;
        }

        /// <summary>
        /// 获取管理员后台导航列表
        /// </summary>
        /// <param name="nav_dt"></param>
        /// <returns></returns>
        protected string GetAdminNavJson()
        {
            string nav_json = string.Empty;

            DataTable nav_dt = GetAdminNav();
            if (nav_dt != null)
            {
                nav_json = JsonHelper.DataTableToJSON(nav_dt);
            }

            return nav_json;
        }

        /// <summary>
        /// 根据父ID获取导航菜单列表
        /// </summary>
        /// <param name="parent_id"></param>
        /// <returns></returns>
        protected DataTable NavList(int parent_id)
        {
            DataTable dt = new BLL.navigation().GetList(0, "channel_id=1 and nav_type='admin' and parent_id=" + parent_id + "", "sort_id asc").Tables[0];

            return dt;
        }
    }
}
